home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 10 code / GWorld Drawing / GWorld Routines / AsmBasics.c next >
Encoding:
C/C++ Source or Header  |  1992-04-08  |  3.6 KB  |  120 lines  |  [TEXT/KAHL]

  1. #include "DemoRoutines.h"
  2.  
  3. long GWGet32PixelAsm( GWorldPtr src, short x, short y )
  4. {
  5. PixMapHandle    srcPixMap;
  6. unsigned short    srcRowBytes;
  7. long            srcBaseAddr;
  8. long            srcAddr;
  9. char            mmuMode;
  10. long            result;
  11.  
  12.     srcPixMap = GetGWorldPixMap( src );
  13.     srcBaseAddr = (long) GetPixBaseAddr ( srcPixMap );    /* get the address of the pixmap */
  14.     mmuMode = true32b;
  15.     SwapMMUMode ( &mmuMode );                        /* set the MMU to 32-bit mode */
  16.  
  17.     asm {
  18.         move.l    srcPixMap,a0
  19.         move.l    srcBaseAddr,a1
  20.         move.l    (a0),a0                ;get ptr to pixmap
  21.         move.w    y,d1                ;get y
  22.         sub.w    6(a0),d1            ;make y bounds 0 relative
  23.         move.w    4(a0),d0            ;get rowbytes
  24.         and.w    #0x7FFF,d0            ;strip bitmap/pixmap bit
  25.         mulu.w    d0,d1                ;calculate offset to beginning of this row
  26.         adda.l    d1,a1                ;calculate address of this row
  27.         moveq    #0,d0                ;extend x to a word
  28.         move.w    x,d0
  29.         sub.w    8(a0),d0            ;make x bounds 0 relative
  30.         lsl.w    #2,d0                ;convert x to pixels (4 bytes/pixel)
  31.         adda.l    d0,a1                ;calculate pixel address
  32.         move.l    (a1),result
  33.     }
  34.     SwapMMUMode ( &mmuMode );                        /* restore the previous MMU mode */
  35.     return( result );
  36. }
  37.  
  38. void GWSet32PixelAsm( GWorldPtr src, short x, short y, long pixelValue )
  39. {
  40. PixMapHandle    srcPixMap;
  41. unsigned short    srcRowBytes;
  42. long            srcBaseAddr;
  43. long            srcAddr;
  44. char            mmuMode;
  45.  
  46.     srcPixMap = GetGWorldPixMap( src );
  47.     srcBaseAddr = (long) GetPixBaseAddr ( srcPixMap );    /* get the address of the pixmap */
  48.     mmuMode = true32b;
  49.     SwapMMUMode ( &mmuMode );                        /* set the MMU to 32-bit mode */
  50.  
  51.     asm {
  52.         move.l    srcPixMap,a0
  53.         move.l    srcBaseAddr,a1
  54.         move.l    (a0),a0                ;get ptr to pixmap
  55.         move.w    y,d1                ;get y
  56.         sub.w    6(a0),d1            ;make y bounds 0 relative
  57.         move.w    4(a0),d0            ;get rowbytes
  58.         and.w    #0x7FFF,d0            ;strip bitmap/pixmap bit
  59.         mulu.w    d0,d1                ;calculate offset to beginning of this row
  60.         adda.l    d1,a1                ;calculate address of this row
  61.         moveq    #0,d0                ;extend x to a word
  62.         move.w    x,d0
  63.         sub.w    8(a0),d0            ;make x bounds 0 relative
  64.         lsl.w    #2,d0                ;convert x to pixels (4 bytes/pixel)
  65.         adda.l    d0,a1                ;calculate pixel address
  66.         move.l    pixelValue,(a1)
  67.     }
  68.     SwapMMUMode ( &mmuMode );                        /* restore the previous MMU mode */
  69. }
  70.  
  71. /*
  72. ** The "Fast" versions of the calls assume they are called in 32-bit addressing mode.
  73. ** The PixMapPtr and srcBaseAddr must be 32-bit clean.
  74. */
  75.  
  76. long FastGWGet32Pixel( PixMap *srcPixMap, long *srcBaseAddr, short x, short y )
  77. {
  78. long    result;
  79.  
  80.     asm {
  81.         move.l    srcPixMap,a0        ;must be 32-bit clean pointer
  82.         move.w    y,d1                ;get y
  83.         sub.w    6(a0),d1            ;make y bounds 0 relative
  84.         move.w    4(a0),d0            ;get rowbytes
  85.         and.w    #0x7FFF,d0            ;strip bitmap/pixmap bit
  86.         mulu.w    d0,d1                ;calculate offset to beginning of this row
  87.         move.l    srcBaseAddr,a1        ;must be 32-bit base address
  88.         adda.l    d1,a1                ;calculate address of this row
  89.         moveq    #0,d0                ;extend x to a word
  90.         move.w    x,d0
  91.         sub.w    8(a0),d0            ;make x bounds 0 relative
  92.         lsl.w    #2,d0                ;convert x to pixels (4 bytes/pixel)
  93.         adda.l    d0,a1                ;calculate pixel address
  94.         move.l    (a1),result
  95.     }
  96.     return( result );
  97. }
  98.  
  99. void FastGWSet32Pixel( PixMap *srcPixMap, long *srcBaseAddr, short x, short y, long pixelValue )
  100. {
  101.  
  102.     asm {
  103.         move.l    srcPixMap,a0        ;must be 32-bit clean pointer
  104.         move.w    y,d1                ;get y
  105.         sub.w    6(a0),d1            ;make y bounds 0 relative
  106.         move.w    4(a0),d0            ;get rowbytes
  107.         and.w    #0x7FFF,d0            ;strip bitmap/pixmap bit
  108.         mulu.w    d0,d1                ;calculate offset to beginning of this row
  109.         move.l    srcBaseAddr,a1        ;must be 32-bit base address
  110.         adda.l    d1,a1                ;calculate address of this row
  111.         moveq    #0,d0                ;extend x to a word
  112.         move.w    x,d0
  113.         sub.w    8(a0),d0            ;make x bounds 0 relative
  114.         lsl.w    #2,d0                ;convert x to pixels (4 bytes/pixel)
  115.         adda.l    d0,a1                ;calculate pixel address
  116.         move.l    pixelValue,(a1)
  117.     }
  118. }
  119.  
  120.